<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<script src="<c:url value='/static/jquery/jquery-1.9.1.min.js'/>" type="text/javascript"></script>
<script type="text/javascript" src="<c:url value='/static/themes/js/jquery.datatables.min.js'/>"></script>
<script type="text/javascript"
	src="<c:url value='/static/datetimepicker/js/bootstrap-datetimepicker.js'/>"
	charset="UTF-8"></script>
	
<title>消息中心</title>
</head>
<body>
	<div class="panel panel-default bk-bg-white">
		<div class="panel-body">
		<form class="form-horizontal">
			<div class="row">
				<div class="form-group col-sm-4">
					<label  class="col-sm-4 control-label">内容关键字：</label> 
					<div class="col-sm-8">
						<input type="text" class="form-control" id="sendContent"  placeholder="内容关键字">
					</div>
				</div>
				<div class="form-group col-sm-4">
					<label  class="col-sm-4 control-label">发布时间：</label> 
					<div class="col-sm-8">
   						<input class="input-append date form_datetime form-control" id="startSendTime" >
						    <span class="add-on"><i class="icon-remove"></i></span>
						    <span class="add-on"><i class="icon-calendar"></i></span>
					</div>
				</div>
				<div class="form-group col-sm-4">
					<label  class="col-sm-1 control-label">-</label>
					<div class="col-sm-8">
   						<input class="input-append date form_datetime form-control" id="endSendTime" >
						    <span class="add-on"><i class="icon-remove"></i></span>
						    <span class="add-on"><i class="icon-calendar"></i></span>
					</div>
				</div>
			</div>
			<div class="form-group col-sm-12" style="padding-bottom: 15px; text-align: center;">
					<button id="search" type="button" class="btn btn-primary glyphicon glyphicon-search"> 搜索</button>
			</div>
		</form>	
		</div>
	</div>
	<!-- panel-body -->
	<div id="message"></div>
	<!-- panel -->
	<div class="panel panel-default">
		<div class="panel-body">
			<div class="table-responsive">
				<div id="table1_wrapper" class="dataTables_wrapper no-footer">
					<div style="width:100%">
						<a href="<c:url value='/info/toAdd' />" style="padding-left: 50%;color:blue" id="toAdd">+新增消息</a>
					</div>
					<table id="table" class="display nowrap" cellspacing="0" width="100%">
						<thead>
							<tr role="row">
								<th>发送时间</th>
								<th>发送者</th>
								<th>接收人</th>
								<th>发送内容</th>
								<th>操作</th>
							</tr>
						</thead>
					</table>
				</div>
			</div>
		</div>
		<div id="page">
			
		</div>
	</div>

	<script type="text/javascript">
	
	
	$(function($) {
		
		//日期控件
		$('#startSendTime').datetimepicker({
			language : 'zh-CN',
			format : 'yyyy-mm-dd hh:ii',
			autoclose : true,
			todayBtn : true,
			minuteStep : 10
		}).on('changeDate', function(ev) {
			var starttime = $(this).val();
			$('#endSendTime').datetimepicker('setStartDate', starttime);
			$(this).datetimepicker('hide');
		});

		$('#endSendTime').datetimepicker({
			language : 'zh-CN',
			format : 'yyyy-mm-dd hh:ii',
			autoclose : true,
			todayBtn : true,
			minuteStep : 10
		}).on('changeDate', function(ev) {
			var time = $(this).val();
			$('#startSendTime').datetimepicker('setEndDate', time);
			$(this).datetimepicker('hide');
		});
		doSearch();
		function doSearch(refresh){
			var table=$('#table').DataTable({
		        "processing": true,
		        "serverSide": true,
		        "bLengthChange": false,
		        "bFilter": false,
		        "bSort":false,
		        "bDestroy":true,
		        "sScrollX": "100%",
		        "sScrollY": "100%",
		        "language": {
		            "url": path+"/static/language_datatables.json"
		        },
		        "ajax": {
		            "url": path+"/info/getInfoList",
		            "type": "POST",
		            "async" : false,
		            "data":{
		                    "sendContent":$('#sendContent').val(),
		                    "startSendTime": $('#startSendTime').val(),
		                    "endSendTime": $('#endSendTime').val()
		            }
		        },
		        "oSearch":{
		        	
		        },
		        "columns": [
		            { "data": "sendtime" ,"width": "20%"},
		            { "data": "username" ,"width": "20%"},
		            { "data": "scope" ,"width": "20%"},
		            { "data": "sendcontent","width": "20%" },
		            { "data": "sysinfoid" ,"width": "20%"}
		        ],
		        "columnDefs": [
	                 {
	                     "render": function ( data, type, row ) {
	                    	 return dateTimeFormatter(data);
	                     },
	                     "targets": 0
	                 },
	                 {
	                     "render": function ( data, type, row ) {
	                    	 if(data&&data.length>20){
	                    		 return data.substring(0,20)+"...";
	                    	 }
	                    	 return data;
	                     },
	                     "targets": 3
	                 },
	                 {
	                     "render": function ( data, type, row ) {
	                    	if(data=='0'){
	                    		return '全部';
	                    	}else if(data=='1'){
	                    		return '全部商家';
	                    	}else if(data=='2'){
	                    		return '全部买手';
	                    	}else if(data=='3'){
	                    		return  '指定范围发布';
	                    	}else{return '';}
	                     },
	                     "targets": 2
	                 },
	                 {
	                     "render": function ( data, type, row ) {
		                    	var ret= '<button class="btn btn-warning detail" key="'+data+'" ">查看</button>&nbsp;'
			                    return ret;
	                     },
	                     "targets": 4
	                 },
	             ]

		    });
		};
		
		//查询事件
		$('#search').click(function(){
			doSearch();
		});
		
		
		bandclick();
		function bandclick(){
			$('body').on("click",'.detail',function(){
				_t = $(this);
				var infoId=_t.attr('key');
				window.location.href=path+'/info/details?infoId='+infoId;
			});
		}
		
		
	});
	
	
	
	
	//显示消息
	function showmessage(msg,callback){
		$('#message').ucMessage({
			msg:msg,
			callback:callback
		});
	}
	 
	</script>
</body>
</html>